
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#include "tests_xrn_core.h"

int test_xrn_base_number_mul(
 )
{
    xgenesis_base_t obase;
    xrn_base_t xb_i;
    xrn_base_t xb_o;
    xrn_vector_t xv_i;
    xrn_vector_t xv_o;
    xnum_t sign;
    xnum_t nmult;
    xmat_t xmat;
    xnum_t tmp;
    xnum_t res_0;
    xnum_t res_1;
    int i;
    traverse_opt_t trav_tmp;

    // maximum value (used to speed up)
    int maxnum;
    int steps;
    int error;

    // the lower the fastes the check
    maxnum = 10;
    xgenesis_base_init( &obase );
    xgenesis_base_v2m( &obase, &xmat );

    // initialize a random sign vector
    xrn_initialize_rnd_num( &sign );

    // initialize xoron base with a random sign
    xb_i.base_matrix = xmat;
    xb_i.sign_vector = sign;

    // initialize a random multiplier vector
    xrn_initialize_rnd_num( &nmult );
    for ( i = ( sizeof( xnum_t ) * 8 ); i > maxnum; i-- ) {
        BIT_SETVAL( nmult, i, false );
    }

    // compute output base
    xrn_base_number_mul( &xb_i, &nmult, &xb_o );

    // bin 2 dec
    steps = 0;
    for ( i = 0; i < ( sizeof( xnum_t ) * 8 ); i++ ) {
        if ( BIT_GET( nmult, i ) ) {
            steps += 1 << i;
        }

    }

    // from xoron base to xoron vector
    xrn_initialize_num( &tmp );
    xv_i.xbase = xb_i;
    xv_i.entry_point = tmp;
    xv_o.xbase = xb_o;
    xv_o.entry_point = tmp;

    // initialize results
    xrn_initialize_num( &res_0 );
    xrn_initialize_num( &res_1 );

    // perform the two traverse
    xrn_vector_traverse( &xv_o, &tmp, &res_1, &res_1, &trav_tmp );
    for ( i = 0; i < steps; i++ ) {
        xrn_vector_traverse( &xv_i, &tmp, &res_0, &res_0, &trav_tmp );
    }

    // assume that there is no error

    XNUM_CMP( res_0, res_1, error );
    if ( error == 0 ) {
        return 0;
    }

    return 1;
}

int test_xrn_matrix_check(
 )
{
    xrn_matrix_t xml;
    int error;

    xgenesis_base_t ob;
    xnum_t cob, cos;
    xrn_vector_t xvl0, xvl1, xvl2;
    int index0, index1;
    int index2, index3;
    int index4, index5;

    xrn_initialize_rnd_num( &cob );
    xrn_initialize_rnd_num( &cos );
    xgenesis_base_init( &ob );
    xgenesis_base_2_xrn_matrix( &ob, &cob, &cos, &xml );

    error = xrn_matrix_check( &xml );
    if ( ( error != XSUCCESS ) && ( error != XINFO_PERMUTED_MATRIX ) ) {
        return 1;
    }

    // inject xrn_doubling error
    index0 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    index1 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    xvl0 = xml.xvector[index0];
    xrn_initialize_rnd_num( &xml.xvector[index0].xbase.base_matrix.xmat[index1] );

    index2 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    index3 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    xvl1 = xml.xvector[index2];
    xrn_initialize_rnd_num( &xml.xvector[index2].xbase.base_matrix.xmat[index3] );

    index4 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    index5 = rand(  ) % ( ( int ) sizeof( xnum_t ) * 8 );
    xvl2 = xml.xvector[index4];
    xrn_initialize_rnd_num( &xml.xvector[index4].xbase.base_matrix.xmat[index5] );

    error = xrn_matrix_check( &xml );
    if ( ( error == XSUCCESS ) || ( error == XINFO_PERMUTED_MATRIX ) ) {
        return 1;
    }

    xml.xvector[index4] = xvl2;
    xml.xvector[index2] = xvl1;
    xml.xvector[index0] = xvl0;

    // inject non linearity error
    xrn_initialize_rnd_num( &xml.xvector[index0].entry_point );
    error = xrn_matrix_check( &xml );
    if ( ( error == XSUCCESS ) || ( error == XINFO_PERMUTED_MATRIX ) ) {
        return 1;
    }

    return 0;
}

int test_xgenesis_base_check(
 )
{
    xgenesis_base_t obase0;
    int error;

    xgenesis_base_init( &obase0 );
    error = xrn_check_genesis_base( &obase0 );
    if ( error != 0 ) {
        return 1;
    }

    // inject a error
    obase0.base_vector[2] = ( uint8_t ) ( obase0.base_vector[2] + 0x01 );
    error += xrn_check_genesis_base( &obase0 ) != XERR_NOT_GENESIS;
    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int test_xrn_dead_code(
 )
{
    xgenesis_base_t obase;
    xrn_base_t xb;
    xrn_vector_t xv;
    xnum_t dc;
    xnum_t sign;
    xnum_t tmp;
    xmat_t xmat;
    int error;
    traverse_opt_t trav_tmp;

    xgenesis_base_init( &obase );
    xgenesis_base_v2m( &obase, &xmat );

    // initialize a random sign vector
    xrn_initialize_rnd_num( &sign );

    // initialize xoron base with a random sign
    xb.base_matrix = xmat;
    xb.sign_vector = sign;

    // compute dead code
    xrn_dead_code( &xb, &dc );

    // compute a number that is different from the dead code
    X_INV2( dc, tmp );

    // initialize a xoron vector with 
    // dummy dead code and entry point
    xv.xbase = xb;
    xv.entry_point = tmp;

    // traverse
    xrn_vector_traverse( &xv, &tmp, &dc, &tmp, &trav_tmp );

    // sanity check (if dead code leads to a dead code)
    XNUM_CMP( tmp, dc, error );
    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int test_xrn_doubling(
 )
{
    xgenesis_base_t obase;
    xrn_base_t xb;
    xrn_base_t xbo;
    xnum_t sign;
    xnum_t point_0;
    xnum_t point_1;
    xnum_t point_2;
    xmat_t xmat;
    int i;
    int error;
    traverse_opt_t trav_tmp;

    xrn_vector_t xv;

    xgenesis_base_init( &obase );
    xgenesis_base_v2m( &obase, &xmat );

    // initialize a random sign vector
    xrn_initialize_rnd_num( &sign );

    // initialize xoron base with a random sign
    xb.base_matrix = xmat;
    xb.sign_vector = sign;

    // assume that there is no error
    error = 0;

    // original origin base
    xbo = xb;

    // test xrn_doubling for function
    for ( i = 0; ( i < ( sizeof( xnum_t ) * 8 ) ) && ( !error ); i++ ) {
        xrn_doubling( &xb, &xb );
        if ( i == ( sizeof( xnum_t ) * 8 ) - 1 ) {

            // check if the Nth result is equal to the beginning
            error = xrn_compare_bases( &xb, &xbo );
        } else {

            // check if the non Nth result is different to the beginning
            error = 1 - xrn_compare_bases( &xb, &xbo );
        }

    }

    // test xrn_doubling for values
    if ( !error ) {
        xrn_initialize_rnd_num( &sign );
        xb.sign_vector = sign;
        xv.xbase = xb;
        xv.entry_point = sign;
        xrn_initialize_rnd_num( &point_0 );
        xrn_vector_traverse( &xv, &sign, &point_0, &point_1, &trav_tmp );
        xrn_vector_traverse( &xv, &sign, &point_1, &point_2, &trav_tmp );
        xrn_doubling( &xb, &xb );
        xv.xbase = xb;
        xrn_vector_traverse( &xv, &sign, &point_0, &point_1, &trav_tmp );
        XNUM_CMP( point_2, point_1, error );
    }

    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int test_xrn_sum_of_bases(
 )
{
    xgenesis_base_t obase;
    xrn_base_t xb;
    xrn_base_t xb_d;
    xrn_base_t xb_s;
    xrn_base_t xb_1;
    xnum_t sign;
    xmat_t xmat;
    int i;
    int error;
    int iterations;
    int iterations_log2;

    xgenesis_base_init( &obase );
    xgenesis_base_v2m( &obase, &xmat );

    // initialize a random sign vector
    xrn_initialize_rnd_num( &sign );

    // initialize xoron base with a random sign
    xb.base_matrix = xmat;
    xb.sign_vector = sign;

    // number of iteration (it should be a power of 2)
    iterations = 16;
    iterations_log2 = 4;

    // xrn_doubling function
    xb_d = xb;
    for ( i = 0; i < iterations_log2; i++ ) {
        xrn_doubling( &xb_d, &xb_d );
    }

    // sum function
    xb_s = xb;
    xb_1 = xb;
    for ( i = 0; i < iterations - 1; i++ ) {
        xrn_sum_of_bases( &xb_1, &xb_s, &xb_s );
    }

    error = xrn_compare_bases( &xb_s, &xb_d );
    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int test_matrix_traverse(
 )
{
    xgenesis_base_t obase;
    xrn_matrix_t xml;
    xnum_t point_0, point_1, point_2, point_22;
    xnum_t pointm_1, pointm_2;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    xnum_t distance;
    int i, j;
    int error;
    uint8_t constant_execution, force_linearity, check_sparcity;
    traverse_opt_t trav_tmp;

    force_linearity = 0;
    check_sparcity = 0;
    constant_execution = ( uint8_t ) rand(  ) % 2;

    xgenesis_base_init( &obase );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_base );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_sign );

    // generate xoron matrix
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, &xml );

    // assume that there is no error
    error = 0;
    xrn_initialize_rnd_num( &point_0 );
    xrn_initialize_num( &distance );
    for ( i = 0; ( i < ( sizeof( xnum_t ) * 8 ) ) && ( !error ); i++ ) {
        j = ( i + 1 ) % ( ( int ) sizeof( xnum_t ) * 8 );

        // check internal xoron vector
        xrn_vector_traverse( &xml.xvector[i], &xml.xrn_dead_code, &point_0, &point_1, &trav_tmp );
        xrn_vector_traverse( &xml.xvector[i], &xml.xrn_dead_code, &point_1, &point_2, &trav_tmp );
        xrn_vector_traverse( &xml.xvector[j], &xml.xrn_dead_code, &point_0, &point_22, &trav_tmp );
        XNUM_CMP( point_2, point_22, error );
        if ( error != 0 ) {
            return 1;
        }

        XNUM_CMP( point_1, point_22, error );
        if ( error == 0 ) {
            return 1;
        }

    }

    xrn_initialize_num( &distance );
    xrn_permute_matrix( &xml );
    for ( i = 0; ( i < ( sizeof( xnum_t ) * 8 ) ) && ( !error ); i++ ) {
        j = ( i + 1 ) % ( ( int ) sizeof( xnum_t ) * 8 );
        // check internal xoron matrix traverse
        BIT_SETVAL( distance, i, true );
        xrn_matrix_traverse( &xml, &point_0, &distance, &pointm_1, &constant_execution, &force_linearity,
                             &check_sparcity );
        xrn_matrix_traverse( &xml, &pointm_1, &distance, &pointm_2, &constant_execution, &force_linearity,
                             &check_sparcity );
        XNUM_CMP( point_1, pointm_1, error );
        if ( error != 0 ) {
            return 1;
        }

        XNUM_CMP( point_2, pointm_2, error );
        if ( error != 0 ) {
            return 1;
        }

    }

    return 0;
}

int test_distances_matrix_traverse(
 )
{
    xgenesis_base_t obase;
    xrn_matrix_t xml;
    xnum_t point_a, point_b, point_c1, point_c2;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    xnum_t distance_ab;
    xnum_t distance_bc;
    xnum_t distance_ac;
    xnum_t zero;
    int carry;
    int error;
    uint8_t constant_execution, force_linearity, check_sparcity;

    constant_execution = ( uint8_t ) rand(  ) % 2;
    force_linearity = 1;
    check_sparcity = 1;

    // a ----> b ----> c

    xgenesis_base_init( &obase );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_base );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_sign );

    // generate xoron matrix
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, &xml );
    xrn_permute_matrix( &xml );

    // assume that there is no error
    xrn_initialize_num( &zero );
    xrn_initialize_rnd_num( &point_a );
    xrn_initialize_rnd_num( &distance_ab );
    xrn_initialize_rnd_num( &distance_bc );

    xrn_matrix_traverse( &xml, &point_a, &distance_ab, &point_b, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_b, &distance_bc, &point_c1, &constant_execution, &force_linearity,
                         &check_sparcity );

    carry = xrn_add_nums( distance_ab, distance_bc, 0, &distance_ac );
    while ( carry == 1 ) {
        carry = xrn_add_nums( distance_ac, zero, 1, &distance_ac );
    }

    xrn_matrix_traverse( &xml, &point_a, &distance_ac, &point_c2, &constant_execution, &force_linearity,
                         &check_sparcity );

    XNUM_CMP( point_c1, point_c2, error );

    if ( error == 1 ) {
        return 1;
    }

    return 0;
}

int test_zero_knowledge_proof_matrix_traverse(
 )
{
    xgenesis_base_t obase;
    xrn_matrix_t xml;
    xnum_t point_a, point_b, point_b2, point_d, point_c1, point_c2;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    xnum_t distance_ab;
    xnum_t distance_ad;
    xnum_t distance_cb;
    xnum_t distance_dc;
    xnum_t distance_bc;
    xnum_t distance_ac;
    xnum_t zero;
    int carry, greater;
    int error, error0, error1;
    uint8_t constant_execution, force_linearity, check_sparcity;

    constant_execution = ( uint8_t ) rand(  ) % 2;
    force_linearity = 1;
    check_sparcity = 1;

    xgenesis_base_init( &obase );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_base );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_sign );

    // generate xoron matrix
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, &xml );
    xrn_permute_matrix( &xml );

    // assume that there is no error
    xrn_initialize_num( &zero );
    xrn_initialize_rnd_num( &point_a );
    xrn_initialize_rnd_num( &distance_ab );
    xrn_initialize_rnd_num( &distance_ad );
    xrn_initialize_rnd_num( &distance_dc );
    xrn_initialize_rnd_num( &distance_cb );
    xrn_initialize_rnd_num( &distance_bc );

    xrn_matrix_traverse( &xml, &point_a, &distance_ab, &point_b, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_a, &distance_ad, &point_d, &constant_execution, &force_linearity,
                         &check_sparcity );

    carry = xrn_add_nums( distance_ad, distance_dc, 0, &distance_ac );
    while ( carry == 1 ) {

        carry = xrn_add_nums( distance_ac, zero, 1, &distance_ac );

    }

    xrn_compare_greater_equal_nums( distance_ac, distance_ab, &greater );

    if ( greater == 1 ) {

        // a ----> b ----> c
        // a -> d -------> c

        xrn_subtract_nums( distance_ac, distance_ab, &distance_bc );

    } else {

        // a ---------------> b
        // a -> d --> c <----

        xrn_subtract_nums( distance_ab, distance_ac, &distance_cb );
    }

    xrn_matrix_traverse( &xml, &point_d, &distance_dc, &point_c1, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_b, &distance_bc, &point_c2, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_c1, &distance_cb, &point_b2, &constant_execution, &force_linearity,
                         &check_sparcity );

    XNUM_CMP( point_c1, point_c2, error0 );
    XNUM_CMP( point_b2, point_b, error1 );
    error = error0 && error1;

    if ( error == 1 ) {
        return 1;
    }

    return 0;

}

int test_zero_knowledge_proof_matrix_traverse_negative(
 )
{
    xgenesis_base_t obase;
    xrn_matrix_t xml;
    xnum_t point_a, point_b, point_b2, point_d, point_c1, point_c2;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    xnum_t distance_ab;
    xnum_t distance_ad;
    xnum_t distance_cb;
    xnum_t distance_dc;
    xnum_t distance_bc;
    xnum_t distance_ac;
    xnum_t distance_ac2;
    xnum_t distance_tmp;
    xnum_t zero;
    int carry, greater;
    int error, error0, error1;
    uint8_t constant_execution, force_linearity, check_sparcity;

    constant_execution = ( uint8_t ) rand(  ) % 2;
    force_linearity = 1;
    check_sparcity = 1;

    xgenesis_base_init( &obase );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_base );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_sign );

    // generate xoron matrix
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, &xml );
    xrn_permute_matrix( &xml );

    // assume that there is no error
    xrn_initialize_num( &zero );
    xrn_initialize_rnd_num( &point_a );
    xrn_initialize_rnd_num( &distance_ab );
    xrn_initialize_rnd_num( &distance_ad );
    xrn_initialize_rnd_num( &distance_dc );
    xrn_initialize_rnd_num( &distance_cb );
    xrn_initialize_rnd_num( &distance_bc );

    xrn_matrix_traverse( &xml, &point_a, &distance_ab, &point_b, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_a, &distance_ad, &point_d, &constant_execution, &force_linearity,
                         &check_sparcity );

    carry = xrn_add_nums( distance_ad, distance_dc, 0, &distance_ac );
    while ( carry == 1 ) {

        carry = xrn_add_nums( distance_ac, zero, 1, &distance_ac );

    }

    xrn_compare_greater_equal_nums( distance_ac, distance_ab, &greater );

    xrn_add_nums( distance_ac, zero, 1, &distance_ac );

    if ( greater == 1 ) {

        // a ----> b ----> c
        // a -> d -------> c

        xrn_subtract_nums( distance_ac, distance_ab, &distance_bc );

    } else {

        // a ---------------> b
        // a -> d --> c <----

        xrn_subtract_nums( distance_ac, distance_ab, &distance_bc );

        X_INV2( distance_bc, distance_cb );
        carry = xrn_add_nums( distance_cb, zero, 1, &distance_cb );
        if ( carry == 1 ) {

            xrn_add_nums( distance_cb, zero, 1, &distance_cb );

        }

        xrn_subtract_nums( zero, distance_ab, &distance_tmp );
        xrn_add_nums( distance_ac, distance_tmp, 0, &distance_bc );

    }

    xrn_matrix_traverse( &xml, &point_d, &distance_dc, &point_c1, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_b, &distance_bc, &point_c2, &constant_execution, &force_linearity,
                         &check_sparcity );
    xrn_matrix_traverse( &xml, &point_c1, &distance_cb, &point_b2, &constant_execution, &force_linearity,
                         &check_sparcity );

    xrn_add_nums( distance_ab, distance_bc, 0, &distance_ac2 );

    XNUM_CMP( point_c1, point_c2, error0 );
    XNUM_CMP( point_b2, point_b, error1 );
    error = error0 && error1;

    if ( error == 1 ) {
        return 1;
    }

    return 0;

}

int test_entry_points(
 )
{
    xgenesis_base_t obase;
    xrn_matrix_t xml;
    xnum_t dc;
    xnum_t dci;
    xnum_t tmp;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    int i;
    int error;
    traverse_opt_t trav_tmp;

    xgenesis_base_init( &obase );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_base );

    // initialize a random number
    xrn_initialize_rnd_num( &change_of_sign );

    // generate xoron matrix
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, &xml );

    // assume that there is no error
    error = 0;

    // check entry points
    // entry point -> dead code -> dead code inverted
    for ( i = 0; ( i < ( sizeof( xnum_t ) * 8 ) ) && ( !error ); i++ ) {
        xrn_vector_traverse( &xml.xvector[i], &xml.xrn_dead_code, &xml.xvector[i].entry_point, &dc,
                             &trav_tmp );
        XNUM_CMP( xml.xrn_dead_code, dc, error );
        if ( error != 0 ) {
            return 1;
        } else {
            X_INV2( xml.xrn_dead_code, dci );
            xrn_vector_traverse( &xml.xvector[i], &xml.xrn_dead_code, &xml.xrn_dead_code, &tmp, &trav_tmp );
            XNUM_CMP( tmp, dci, error );
            if ( error != 0 ) {
                return 1;
            }

        }

    }

    return 0;
}

int test_io(
 )
{
    xrn_point_t point, point2;
    xgenesis_base_t obase;
    xgenesis_base_t obase2;
    xrn_base_t *xb;
    xrn_base_t *xb2;
    xrn_vector_t *xvl;
    xrn_vector_t *xvl2;
    xrn_matrix_t *xml;
    xrn_matrix_t *xml2;
    xrn_matrix_compressed_t *xmc;
    xrn_matrix_compressed_t *xmc2;
    xnum_t tmp;
    xnum_t change_of_base;
    xnum_t change_of_sign;
    xmat_t xmat;
    int i, error;
    xrn_crypto_extra_settings_t settings;
    XBIT_TYPE neq;
    char buffer[256];

    char *str = "../cache/to_remove_file_test.txt";

    FILE *fp;

    for ( i = 0; i < sizeof( settings.encoding_settings ); i++ ) {
        ( ( uint8_t * ) & settings.encoding_settings )[i] = 0;
    }

    settings.encoding_settings.o_settings.mode = std_parameters;
    settings.encoding_settings.o_settings.check_mode = xrn_automatic;
    settings.encoding_settings.i_settings.mode = std_parameters;
    settings.encoding_settings.i_settings.check_mode = xrn_automatic;

    // allocate memory

    // initialize origin base
    xrn_initialize_genesis_base( &obase );
    obase.base_vector[30] = 0x01;       //240
    obase.base_vector[22] = 0x02;       //177
    obase.base_vector[15] = 0x01;       //120
    xgenesis_base_v2m( &obase, &xmat );

    // initialize xoron base with a random sign
    xb = ( xrn_base_t * ) malloc( sizeof( xrn_base_t ) );
    xb->base_matrix = xmat;
    xrn_initialize_rnd_num( &tmp );
    xb->sign_vector = tmp;

    // initialize a random xoron vector 
    xvl = ( xrn_vector_t * ) malloc( sizeof( xrn_vector_t ) );
    xvl->xbase = *xb;
    xrn_initialize_rnd_num( &tmp );
    xvl->entry_point = tmp;

    // initialize a xoron matrix
    xml = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &change_of_base );
    xrn_initialize_rnd_num( &change_of_sign );
    xgenesis_base_2_xrn_matrix( &obase, &change_of_base, &change_of_sign, xml );

    // decompress
    xmc = ( xrn_matrix_compressed_t * ) malloc( sizeof( xrn_matrix_compressed_t ) );
    xrn_initialize_matrix_compressed( xmc );
    xrn_initialize_rnd_num( &xmc->change_of_base );
    xrn_initialize_rnd_num( &xmc->change_of_sign );
    xmc->xgenesis_base = obase;
    error = 0;

    // initalize xrn_point
    strcpy( buffer, "random" );
    xrn_make_point( &point, buffer );

    // test io

    // origin base
    fp = fopen( str, "wb" );
    xrn_dump_point( point, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_point( &point2, fp, settings );
    fclose( fp );
    XNUM_CMP( point.point, point2.point, neq );
    error += neq;
    remove( str );

    // origin base
    fp = fopen( str, "wb" );
    xrn_dump_genesis_base( &obase, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_genesis_base( fp, &obase2, settings );
    fclose( fp );
    error += xrn_compare_genesis_bases( &obase, &obase2 );
    remove( str );

    // xoron base
    xb2 = ( xrn_base_t * ) malloc( sizeof( xrn_base_t ) );
    fp = fopen( str, "wb" );
    xrn_dump_base( xb, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_base( fp, xb2, settings );
    fclose( fp );
    error += xrn_compare_bases( xb, xb2 );
    remove( str );
    free( xb );
    free( xb2 );

    // xoron matrix light
    xml2 = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    fp = fopen( str, "wb" );
    xrn_dump_matrix( xml, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_matrix( fp, xml2, settings );
    fclose( fp );
    error += xrn_compare_matrices( xml, xml2 );
    remove( str );
    free( xml );
    free( xml2 );

    // xoron matrix light
    xvl2 = ( xrn_vector_t * ) malloc( sizeof( xrn_vector_t ) );
    fp = fopen( str, "wb" );
    xrn_dump_vector( xvl, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_vector( fp, xvl2, settings );
    fclose( fp );
    error += xrn_compare_vectors( xvl, xvl2 );
    remove( str );
    free( xvl );
    free( xvl2 );

    // xoron matrix compressed
    xmc2 = ( xrn_matrix_compressed_t * ) malloc( sizeof( xrn_matrix_compressed_t ) );
    fp = fopen( str, "wb" );
    xrn_dump_matrix_compressed( xmc, fp, settings );
    fclose( fp );
    fp = fopen( str, "rb" );
    xrn_load_matrix_compressed( fp, xmc2, settings );
    fclose( fp );
    error += xrn_compare_matrices_compressed( xmc, xmc2 );
    remove( str );
    free( xmc );
    free( xmc2 );
    if ( error != 0 ) {
        return 1;
    }

    return 0;
}

int origin2xrn_base(
 )
{
    xgenesis_base_t obase_0;
    xgenesis_base_t obase_1;
    xmat_t xmat_0;
    xmat_t xmat_1;
    int i;
    int error0;

    // initalize origin base at random
    for ( i = 0; i < XNBYTES_ORIGIN; i++ ) {
        obase_0.base_vector[i] = ( uint8_t ) rand(  ) % 256;
    }

    // convert origin base to matrix back and forth
    xgenesis_base_v2m( &obase_0, &xmat_0 );
    xgenesis_base_m2v( &xmat_0, &obase_1 );
    xgenesis_base_v2m( &obase_1, &xmat_1 );

    // assume that there is no error

    if ( xrn_compare_genesis_bases( &obase_0, &obase_1 ) ) {
        return 1;
    }

    XMAT_CMP( xmat_0, xmat_1, error0 );
    if ( error0 != 0 ) {
        return 1;
    }

    return 0;
}

int test_all_traverses(
 )
{
    xnum_t num0;
    xnum_t num1;
    xnum_t num2;
    xnum_t num3;
    int neq, ret;
    uint8_t constant_execution;
    uint8_t force_linearity;
    uint8_t check_sparcity;

    xrn_matrix_t *xm;
    xnum_t cob, cos;
    xgenesis_base_t *ob;

    force_linearity = ( uint8_t ) rand(  ) % 2;
    check_sparcity = 0;

    // origin base
    ob = ( xgenesis_base_t * ) malloc( sizeof( xgenesis_base_t ) );
    xgenesis_base_init( ob );

    // generate xoron matrix
    xm = ( xrn_matrix_t * ) malloc( sizeof( xrn_matrix_t ) );
    xrn_initialize_rnd_num( &cob );     // change of base
    xrn_initialize_rnd_num( &cos );     // change of sign

    xgenesis_base_2_xrn_matrix( ob, &cob, &cos, xm );
    free( ob );

    xrn_initialize_rnd_num( &num0 );
    xrn_initialize_rnd_num( &num1 );

    xrn_permute_matrix( xm );

    constant_execution = 0;
    ret =
        xrn_matrix_traverse( xm, &num0, &num1, &num2, &constant_execution, &force_linearity,
                             &check_sparcity );

    if ( ( ret != XSUCCESS ) && ( ret != XERR_NLINEAR ) ) {

        free( xm );
        return 1;
    }

    constant_execution = 1;

    ret =
        xrn_matrix_traverse( xm, &num0, &num1, &num3, &constant_execution, &force_linearity,
                             &check_sparcity );

    if ( ( ret != XSUCCESS ) && ( ret != XERR_NLINEAR ) ) {
        free( xm );
        return 1;
    }

    XNUM_CMP( num2, num3, neq );

    if ( ( neq == 1 ) || ( ret != XSUCCESS ) ) {
        free( xm );
        return 1;
    }

    num0 = xm->xrn_dead_code;
    force_linearity = 1;
    ret =
        xrn_matrix_traverse( xm, &num0, &num1, &num3, &constant_execution, &force_linearity,
                             &check_sparcity );

    if ( ret == XSUCCESS ) {
        free( xm );
        return 1;
    }

    free( xm );
    return 0;

}

int test_all_xrn_core( FILE * fp, int runs, int non_block
 )
{
    time_t t;
    char buff[256];
    int v_origin2xrn_base;
    int v_test_xrn_dead_code;
    int v_test_xrn_doubling;
    int v_test_matrix_traverse;
    int v_test_entry_points;
    int v_test_xrn_sum_of_bases;
    int v_test_io;
    int v_test_xgenesis_base_check;
    int v_test_xrn_base_number_mul;
    int v_test_xrn_matrix_check;
    int v_test_distances_matrix_traverse;
    int v_test_zero_knowledge_proof_matrix_traverse_negative;
    int v_test_zero_knowledge_proof_matrix_traverse;
    int v_test_all_traverses;

    srand( ( unsigned ) time( &t ) );
    int error;
    int occ;

    error = 0;

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_matrix_traverse = test_matrix_traverse(  );
        error += v_test_matrix_traverse;
        printf( "[%4d]", occ );
        if ( !v_test_matrix_traverse ) {
            printf( "test_xrn_core -> mtraverse passed\n" );
            fprintf( fp, "test_xrn_core -> mtraverse passed\n" );
        } else {
            printf( "test_xrn_core -> mtraverse failed\n" );
            fprintf( fp, "test_xrn_core -> mtraverse failed\n" );
        }

        if ( v_test_matrix_traverse != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_all_traverses = test_all_traverses(  );
        error += v_test_all_traverses;
        printf( "[%4d]", occ );
        if ( !v_test_all_traverses ) {
            printf( "test_xrn_core -> test_all_traverses passed\n" );
            fprintf( fp, "test_xrn_core -> test_all_traverses passed\n" );
        } else {
            printf( "test_xrn_core -> test_all_traverses failed\n" );
            fprintf( fp, "test_xrn_core -> test_all_traverses failed\n" );
        }

        if ( v_test_all_traverses != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_io = test_io(  );
        error += v_test_io;
        printf( "[%4d]", occ );
        if ( !v_test_io ) {
            printf( "test_xrn_core -> test_io passed\n" );
            fprintf( fp, "test_xrn_core -> test_io passed\n" );
        } else {
            printf( "test_xrn_core -> test_io failed\n" );
            fprintf( fp, "test_xrn_core -> test_io failed\n" );
        }

        if ( v_test_io != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_matrix_check = test_xrn_matrix_check(  );
        error += v_test_xrn_matrix_check;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_matrix_check ) {
            printf( "test_xrn_core -> test_xrn_matrix_check passed\n" );
            fprintf( fp, "test_xrn_core -> test_xrn_matrix_check passed\n" );
        } else {
            printf( "test_xrn_core -> test_xrn_matrix_check failed\n" );
            fprintf( fp, "test_xrn_core -> test_xrn_matrix_check failed\n" );
        }

        if ( v_test_xrn_matrix_check != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_zero_knowledge_proof_matrix_traverse = test_zero_knowledge_proof_matrix_traverse(  );
        error += v_test_zero_knowledge_proof_matrix_traverse;
        printf( "[%4d]", occ );
        if ( !v_test_zero_knowledge_proof_matrix_traverse ) {
            printf( "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse passed\n" );
            fprintf( fp, "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse passed\n" );
        } else {
            printf( "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse failed\n" );
            fprintf( fp, "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse failed\n" );
        }

        if ( v_test_zero_knowledge_proof_matrix_traverse != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_zero_knowledge_proof_matrix_traverse_negative =
            !test_zero_knowledge_proof_matrix_traverse_negative(  );
        error += v_test_zero_knowledge_proof_matrix_traverse_negative;
        printf( "[%4d]", occ );
        if ( !v_test_zero_knowledge_proof_matrix_traverse_negative ) {
            printf( "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse_negative passed\n" );
            fprintf( fp, "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse_negative passed\n" );
        } else {
            printf( "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse_negative failed\n" );
            fprintf( fp, "test_xrn_core -> test_zero_knowledge_proof_matrix_traverse_negative failed\n" );
        }

        if ( v_test_zero_knowledge_proof_matrix_traverse_negative != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_distances_matrix_traverse = test_distances_matrix_traverse(  );
        error += v_test_distances_matrix_traverse;
        printf( "[%4d]", occ );
        if ( !v_test_distances_matrix_traverse ) {
            printf( "test_xrn_core -> test_distances_matrix_traverse passed\n" );
            fprintf( fp, "test_xrn_core -> test_distances_matrix_traverse passed\n" );
        } else {
            printf( "test_xrn_core -> test_distances_matrix_traverse failed\n" );
            fprintf( fp, "test_xrn_core -> test_distances_matrix_traverse failed\n" );
        }

        if ( v_test_distances_matrix_traverse != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_matrix_traverse = test_matrix_traverse(  );
        error += v_test_matrix_traverse;
        printf( "[%4d]", occ );
        if ( !v_test_matrix_traverse ) {
            printf( "test_xrn_core -> test_matrix_traverse passed\n" );
            fprintf( fp, "test_xrn_core -> test_matrix_traverse passed\n" );
        } else {
            printf( "test_xrn_core -> test_matrix_traverse failed\n" );
            fprintf( fp, "test_xrn_core -> test_matrix_traverse failed\n" );
        }

        if ( v_test_matrix_traverse != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_base_number_mul = test_xrn_base_number_mul(  );
        error += v_test_xrn_base_number_mul;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_base_number_mul ) {
            printf( "test_xrn_core -> xrn_base_number_mul passed\n" );
            fprintf( fp, "test_xrn_core -> xrn_base_number_mul passed\n" );
        } else {
            printf( "test_xrn_core -> xrn_base_number_mul failed\n" );
            fprintf( fp, "test_xrn_core -> xrn_base_number_mul failed\n" );
        }

        if ( v_test_xrn_base_number_mul != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_origin2xrn_base = origin2xrn_base(  );
        error += v_origin2xrn_base;
        printf( "[%4d]", occ );
        if ( !v_origin2xrn_base ) {
            printf( "test_xrn_core -> origin2xoron passed\n" );
            fprintf( fp, "test_xrn_core -> origin2xoron passed\n" );
        } else {
            printf( "test_xrn_core -> origin2xoron failed\n" );
            fprintf( fp, "test_xrn_core -> origin2xoron failed\n" );
        }

        if ( v_origin2xrn_base != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xgenesis_base_check = test_xgenesis_base_check(  );
        error += v_test_xgenesis_base_check;
        printf( "[%4d]", occ );
        if ( !v_test_xgenesis_base_check ) {
            printf( "test_xrn_core -> test_xgenesis_base_check passed\n" );
            fprintf( fp, "test_xrn_core -> test_xgenesis_base_check passed\n" );
        } else {
            printf( "test_xrn_core -> test_xgenesis_base_check failed\n" );
            fprintf( fp, "test_xrn_core -> test_xgenesis_base_check failed\n" );
        }

        if ( v_test_xgenesis_base_check != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_entry_points = test_entry_points(  );
        error += v_test_entry_points;
        printf( "[%4d]", occ );
        if ( !v_test_entry_points ) {
            printf( "test_xrn_core -> test_entry_point passed\n" );
            fprintf( fp, "test_xrn_core -> test_entry_point passed\n" );
        } else {
            printf( "test_xrn_core -> test_entry_point failed\n" );
            fprintf( fp, "test_xrn_core -> test_entry_point failed\n" );
        }

        if ( v_test_entry_points != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_doubling = test_xrn_doubling(  );
        error += v_test_xrn_doubling;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_doubling ) {
            printf( "test_xrn_core -> xrn_doubling passed\n" );
            fprintf( fp, "test_xrn_core -> xrn_doubling passed\n" );
        } else {
            printf( "test_xrn_core -> xrn_doubling failed\n" );
            fprintf( fp, "test_xrn_core -> xrn_doubling failed\n" );
        }

        if ( v_test_xrn_doubling != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_dead_code = test_xrn_dead_code(  );
        error += v_test_xrn_dead_code;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_dead_code ) {
            printf( "test_xrn_core -> xrn_dead_code passed\n" );
            fprintf( fp, "test_xrn_core -> xrn_dead_code passed\n" );
        } else {
            printf( "test_xrn_core -> xrn_dead_code failed\n" );
            fprintf( fp, "test_xrn_core -> xrn_dead_code failed\n" );
        }

        if ( v_test_xrn_dead_code != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    for ( occ = 0; ( occ < runs ) && ( ( error == 0 ) || non_block ); occ++ ) {
        srand( ( unsigned ) time( &t ) + ( unsigned ) occ );
        v_test_xrn_sum_of_bases = test_xrn_sum_of_bases(  );
        error += v_test_xrn_sum_of_bases;
        printf( "[%4d]", occ );
        if ( !v_test_xrn_sum_of_bases ) {
            printf( "test_xrn_core -> xrn_sum_of_bases passed\n" );
            fprintf( fp, "test_xrn_core -> xrn_sum_of_bases passed\n" );
        } else {
            printf( "test_xrn_core -> xrn_sum_of_bases failed\n" );
            fprintf( fp, "test_xrn_core -> xrn_sum_of_bases failed\n" );
        }

        if ( v_test_xrn_sum_of_bases != 0 ) {
#if ( XRN_GNU_LINUX == 1 )
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %ld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %ld \n", t );
#else
            sprintf( buff, "TEST_CORE_LIB FAILED SEED %lld ", t );
            fprintf( fp, "TEST_CORE_LIB FAILED SEED %lld \n", t );
#endif
            printf( "%s", buff );
        }

    }

    return error;
}

